package ink.lovejinhu.GoldenCodeOfProgrammerInterview;

import java.util.HashMap;

/**
 * @author jinhu
 * created 2021-08-10 8:46
 */
public class Interview_0104 {
    public boolean canPermutePalindrome(String s) {
        HashMap<Character, Integer> hashMap = new HashMap<>();

        for (int i = 0; i < s.length(); i++) {
            if (hashMap.containsKey(s.charAt(i))) {
                hashMap.put(s.charAt(i), hashMap.get(s.charAt(i)) + 1);
            } else {
                hashMap.put(s.charAt(i), 1);
            }
        }
        int flag = 0;
        for (Character v0 : hashMap.keySet()
        ) {
            if (hashMap.get(v0) % 2 == 0) {
                continue;
            } else {
                if (flag == 1) {
                    return false;
                } else {
                    flag++;
                }
            }
        }
        return true;
    }
}
